<template>
    <div class="header_r flex" style="padding: 5px;">
        <addStockInView ref="addStockInView" />

        <div class="serachBox flex" style="margin-left: 15px;">
            <div class="flex">
                <p>物资名称</p>
            </div>
            <input type="text" v-model="nameValue">
            <button @click="getMylist">搜索</button>
        </div>
        <div class="addbtn flex" @click="stockInAdd" v-if="false">
            <img src="../../assets/room_add_icon.png" style="width: 13px;height: 13px;margin-right: 5px;" />
            <p>新建入库单</p>
        </div>
        <div class="addbtn flex" v-loading.fullscreen.lock="fullscreenLoading" @click="exportExcel">
            <p>导出明细</p>
        </div>
    </div>
    <div class="table_box">
        <el-table :data="list" border style="width: 100%;" scrollTo fit="false" :row-class-name="tableRowClassName"
            :header-cell-style="headerCellStyle" :row-style="tableRowStyle">
            <el-table-column type="index" label="序号" width="150px">
                <template #header>
                    <div class="header_icon">
                        <span>序号</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="batchNo" label="批次号">
                <template #header>
                    <div class="header_icon">
                        <span>批次号</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="materialName" label="物资名称">
                <template #header>
                    <div class="header_icon">
                        <span>物资名称</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="quantity" label="入库数量">
                <template #header>
                    <div class="header_icon">
                        <span>入库数量</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="price" label="单价">
                <template #header>
                    <div class="header_icon">
                        <span>单价</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="availableQuantity" label="可用数量">
                <template #header>
                    <div class="header_icon">
                        <span>可用数量</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>

            <el-table-column prop="updatedAt" label="入库时间">
                <template #header>
                    <div class="header_icon">
                        <span>入库时间</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>

            <el-table-column prop="supplier" label="供应商">
                <template #header>
                    <div class="header_icon">
                        <span>供应商</span>
                        <el-icon class="rotate">
                            <MoreFilled />
                        </el-icon>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <el-config-provider :locale="locale">
        <div style="margin-top: 10px" class="pageBox flex">
            <el-pagination :total="total" :current-page="page" :page-size="size" background
                layout="prev, pager, next, sizes" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                @size-change="changePageSize" @current-change="changeCurrentPage" />
            <div class="flex">
                <p>第 {{ page }} 条</p>
                <p>共 {{ total }} 条数据</p>
            </div>
        </div>
    </el-config-provider>

</template>
<script>
import { httpService } from "@/utils/httpService";
import { ElConfigProvider, ElMessage, ElLoading } from "element-plus";
import { MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown } from "@element-plus/icons-vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import addStockInView from "./addStockInView.vue"


export default {
    name: "MedicalProductLogin",
    components: { ElMessage, ElLoading, addStockInView, MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, ElConfigProvider },
    data() {
        return {
            page: 1,
            pageSize: 10,
            total: 0,
            list: [],
            nameValue: "",
            fullscreenLoading: false,

        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    computed: {},
    mounted() {
        this.getMylist()
    },
    methods: {
        tableRowClassName({ row, rowIndex }) {
            // console.log(rowIndex);
            return rowIndex % 2 === 1 ? 'warning-row' : '';
        },
        headerCellStyle() {
            return {
                background: '#f2f2f2',
            };
        },
        tableRowStyle({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return {
                    background: '#F5F5F5',
                };
            }
        },

        changePageSize(size) {
            this.pageSize = size;
            this.getMylist()
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getMylist()
        },

        getMylist() {
            httpService(`/javaApi/stockIn/list/${this.page}/${this.pageSize}`, { materialName: this.nameValue }, "get").then(
                (data) => {
                    if (data.list) {
                        data.list.map(item => item.updatedAt = item.updatedAt.slice(0, 10))
                        this.list = data.list
                        this.total = data.total
                    }
                }
            );
        },
        stockInAdd() {
            this.$refs.addStockInView.flag = true
            this.$refs.addStockInView.getMaterialList()
        },

        exportExcel() {
            this.fullscreenLoading = true
            httpService(
                "/javaApi/stockIn/exportExcel", {}, "get"
            ).then((data) => {
                this.fullscreenLoading = false
                window.open(data.message, "_blank")
            });
        },
    },
};
</script>
<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

/* .container {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    padding: 15px 15px;
    background-color: #EEF7FB;
}

.main {
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
} */

.header {
    height: 45px;
    /* background-color: chocolate; */
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header_btn {
    width: 99px;
    height: 32px;
    background-color: #6F72FF;
    border-radius: 5px;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    margin-right: 15px;
    cursor: pointer;
}

.header_btn img {
    width: 17px;
    height: 18px;
    margin-right: 5px;
}

.serachBox {
    color: #666666;
    font-size: 14px;
    width: 333px;
    height: 36px;
    border: 1px solid #D0D0D0;
    box-sizing: border-box;
    border-radius: 20px;
}

.serachBox .flex {
    justify-content: center;
    border-right: 1px solid #D0D0D0;
    margin-right: 10px;
    padding: 0 5px 0 15px;
    color: #666666;
    cursor: pointer;
}

.serachBox input {
    height: calc(100% - 4px);
    border: none;
    outline: none;
    flex: 1;
}

.serachBox button {
    width: 59px;
    height: 30px;
    border-radius: 15px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-right: 2px;
    cursor: pointer;
    line-height: 1;
    outline: none;
}

.addbtn {
    width: 110px;
    height: 32px;
    border-radius: 5px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-left: 15px;
    cursor: pointer;
    outline: none;
    line-height: 1;
    justify-content: center;
}

.borderBox {
    height: calc(100% - 60px);
    border: 1px solid #DFDFDF;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 15px;
}

.borderTop {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.workList {
    display: flex;
}

.workList p {
    color: #666;
    font-size: 14px;
    margin-left: 20px;
}

.workList p span {
    color: #6F72FF;
}

.borderTop .flex {
    margin-right: 20px;
}

.borderTop_btn {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #666666;
    margin-left: 40px;
    cursor: pointer;
}

.header_icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table_box {
    width: calc(100vw - 283px);
    height: calc(100% - 0px);
    overflow-y: auto;
    /* background-color: slategrey; */
}

.el-table {
    /* margin-left: -1px; */
}

.rotate {
    transform: rotate(90deg);
}


.el-scrollbar__bar {
    z-index: 11;
    overflow-x: hidden;
    position: sticky;
}

.el-table.el-table--border {
    overflow: unset;
}


.pageBox {
    background-color: #f6f6f6;
    padding: 5px 0;
    border-top: 1px solid #e7e7e7;
    border-radius: 0 0 5px 5px;
}

.el-pagination {
    margin-left: 10px;
}

.pageBox {
    justify-content: space-between;
}

.pageBox .flex {
    color: #666;
    font-size: 14px;
    margin-right: 10px;
}

.pageBox .flex p {
    color: #666;
    font-size: 14px;
    margin-right: 20px;
}
</style>